home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / shell / m / src / main.c < prev    next >
C/C++ Source or Header  |  1995-04-26  |  7KB  |  260 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <winb.h>
  5. #include <te.h>
  6. #include <fntb.h>
  7. #include <gui.h>
  8. #include <egb.h>
  9. #include <guidbg.h>
  10.  
  11. char    *guiEgbPtr ;            /*    EGB のワークアドレス    */
  12.  
  13. int    DialogID = -1 ;
  14. int    MessageID[2] = -1 ;
  15. int    IconID = -1 ;
  16.  
  17. #include <eintm.h>
  18. //#define DEBUG
  19.  
  20. /*= リジューム用設定=================================================*/
  21. #define RSM_BUFSIZE (300)
  22. FRAME    RSM_FRAME;
  23. char    RSMID[]="%%% m %%%";
  24. char    RSMTITLE[]="m                               By 機拡";
  25.  
  26. int exitFuncRet = ILLEGAL_FUNCTION ;
  27. unsigned int beforeMem = 0;
  28. //short count = 0;
  29. char mes1[] = "888,888,888 -> 888,888,888\0\0";
  30. char mes2[] = "+888,888,888\0\0";
  31.  
  32. int userFunc(apliId, messId, info, data)
  33. int    apliId;
  34. int    messId;
  35. int    info;
  36. int    data;
  37. {
  38.     register int    ret;
  39.  
  40.     ret = ILLEGAL_FUNCTION;
  41.  
  42.     switch(messId)
  43.     {
  44.         case    GM_QUIT :
  45.             MMI_SendMessage( IconID, MM_EXEC, 2, 0, 0 );
  46.             ret = exitFuncRet ;
  47.             break;
  48.     }
  49.  
  50.     return(ret);
  51. }
  52.  
  53. void main()
  54. {
  55.     static MMICTRL mmi ={
  56.                 SCREEN16 | SCREENIGNORE,    // ページ0側解像度
  57.                 SCREENUNUSED,                // ページ1側解像度
  58.                 0,                             // 書き込みページ
  59.                 SCREENAVAILABLE,             // 表示ページ
  60.                 0,                             // 表示プライオリティ
  61.                 SCREENAVAILABLE,            // 色数
  62.                 SCREENEXPAND,                 // VRAMの横の長さ
  63.                 0,                             // メモリ領域の大きさ
  64.                 NULL,                         // メモリ領域のアドレス
  65.                 0,                             // ユーザ領域の大きさ
  66.                 NULL,                         // ユーザ領域のアドレス
  67.                 0, 0,                         // 画面枠    lupx,lupy
  68.                 0, 0,                        //            rdwx,rdwy
  69.                 -16384, -16384,                // 移動枠    lupx,lupy
  70.                 16383, 16383,                //            rdwx,rdwy
  71.                 15,                         // 白色
  72.                 8,                          // 黒色
  73.                 7,                          // 灰色
  74.                 6                             // 反転色
  75.     };
  76.  
  77.     extern int APL_init() ;
  78.     extern int APL_end() ;
  79.  
  80.     /*    初期化処理    */
  81.     if (MMI_Open( &mmi ) == NOERR)
  82.     {
  83.         /*    初期化に成功すればメインループに入る.    */
  84.         if (APL_init() == NOERR){
  85.             MMI_ExecSystem() ;
  86.             APL_end();
  87.             }
  88.     }
  89.  
  90.     /*    終了処理    */
  91.     MMI_Close() ;
  92.  
  93. }
  94.  
  95. int APL_init()
  96. {
  97.     extern MMIINIT    initDataMGUI ;
  98.  
  99.     register int    ret ;
  100.  
  101.     /*    EGB ワークアドレスの取得.    */
  102.     guiEgbPtr = MMI_GetEgbPtr() ;
  103.  
  104.     /*    ハイパ型部品の初期化            */
  105.     if ((ret = MMI_initHyper()) < 0)
  106.         return ret ;
  107.     /*    ダイアログ型部品の初期化        */
  108.     if ((ret = MMI_initDialogL40()) < 0)
  109.         return ret ;
  110.     /*    メッセージ型部品の初期化        */
  111.     if ((ret = MMI_initMessageL40()) < 0)
  112.         return ret ;
  113.     /*    ボタン型部品の初期化            */
  114.     if ((ret = MMI_initButtonL40()) < 0)
  115.         return ret ;
  116.     /*    アイコンボタン型部品の初期化    */
  117.     if ((ret = MMI_initIconL40()) < 0)
  118.         return ret ;
  119.  
  120.     /*    背景データの初期化                        */
  121.  
  122.     /*    データの登録        */
  123.     if ((ret = MMI_Init(&initDataMGUI)) < 0)
  124.         return ret ;
  125.  
  126.     /*----------------------------------------------------------------*/
  127.     /*  リジューム読み込み (※のついた処理は必ず行ってください)       */
  128.     /*----------------------------------------------------------------*/
  129.     char    work[RSMWORKSIZE];    // リジュームマネージャのワークエリア
  130.     char    buf[RSM_BUFSIZE];
  131.     char    *ptr;
  132.     int        size, x, y;
  133.     HYPER    hyp;
  134.  
  135.     // リジュームマネージャの初期化
  136.     EIN_rsmInit( work, RSMID );
  137.     // 読み込みバッファ設定
  138.     EIN_rsmBufSet( work, buf, RSM_BUFSIZE );
  139.     // リジューム情報読み込み
  140.     size = EIN_rsmLoad( work );
  141.     #ifdef DEBUG
  142.     printf("load RSM_SIZE:%d\n",size);
  143.     #endif
  144.     if ( size > 0 ){
  145.         // 表示位置
  146.         if ( ((ptr = strstr(buf,"\nPANEL: ")) != NULL ) &&
  147.              (sscanf(ptr,"\nPANEL: %d %d\n", &x, &y) > 1 ) ){
  148.             // 枠座標を得る
  149.             MMI_SendMessage( DialogID, MM_GETHYPER, 1, &hyp );
  150.             RSM_FRAME.lupx = x;
  151.             RSM_FRAME.lupy = y;
  152.             RSM_FRAME.rdwx = x+(hyp.fr.rdwx-hyp.fr.lupx);
  153.             RSM_FRAME.rdwy = y+(hyp.fr.rdwy-hyp.fr.lupy);
  154.             #ifdef DEBUG
  155.             printf("m:move to (%d,%d)\n",x,y);
  156.             #endif
  157.             MMI_SendMessage( DialogID, MM_MOVE, 1, &RSM_FRAME ) ;
  158.         }
  159.     }
  160.  
  161.     /*    Tmenuにパレットを合わせる    */
  162.     EIN_initGuiColor();
  163.  
  164.     /*    背景を表示する                            */
  165.     MMI_SendMessage(MMI_GetBaseObj(), MM_SHOW, 0) ;
  166.  
  167.     MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc);
  168.     MMI_CallMessage(MMI_GetApliId(), GM_TITLE, (int)RSMTITLE, 0);
  169.  
  170.     extern void    userIdleTask();        /*    登録するアイドルタスク    */
  171.     MMI_SetIdleTaskFunc( userIdleTask );
  172.     userIdleTask();
  173.  
  174.     return NOERR ;
  175. }
  176.  
  177. int APL_end()
  178. {
  179.     /*===================================================================*/
  180.     /* リジューム情報更新 (※がついた処理は必ず行って下さい)             */
  181.     /*===================================================================*/
  182.     char    work[RSMWORKSIZE];
  183.     char    buf[RSM_BUFSIZE];
  184.     char    aplpath[128];
  185.     HYPER    hyp;
  186.     register int ret;
  187.     
  188.     // 枠座標を得る
  189.     MMI_SendMessage( DialogID, MM_GETHYPER, 1, &hyp );
  190.     
  191.     // 移動していたらセーブ
  192.     if ( (RSM_FRAME.lupx  != hyp.fr.lupx) ||
  193.          (RSM_FRAME.lupy  != hyp.fr.lupy) ){
  194.         // マネージャ初期化
  195.         EIN_rsmInit( work, RSMID );
  196.         // バッファ設定(アプリ識別ID,更新時刻は自動設定されます)
  197.         EIN_rsmBufSet( work, buf, RSM_BUFSIZE );
  198.         // アプリディレクトリ保存
  199.         MMI_CallMessage( MMI_GetApliId(), GM_QUERYID, QM_PATH, (int)aplpath );
  200.         EIN_rsmBufPrintf( work, "APLPATH: %s", aplpath );
  201.         // アプリ名保存
  202.         EIN_rsmBufPrintf( work, "TITLE:   %s", RSMTITLE );
  203.         // コメント保存
  204.         EIN_rsmBufCat( work, "COMMENT: フリーメモリを刻々と表示します。標準出力にもprintfします。");
  205.         // アイコン位置保存
  206.         EIN_rsmBufPrintf( work, "PANEL: %d %d", hyp.fr.lupx, hyp.fr.lupy );
  207.         // バッファ終端(^A)設定
  208.         EIN_rsmBufTail( work );
  209.         // バッファをセーブ
  210.         ret = EIN_rsmSave( work );
  211.         #ifdef DEBUG
  212.         printf("save RSM_SIZE:%d\n",ret);
  213.         #endif
  214.     }
  215.  
  216.     return NOERR ;
  217. }
  218.  
  219. void userIdleTask(void)
  220. {
  221.     unsigned int mem,i;
  222.     int p,l;
  223.     p = TL_checkMemory(0);
  224.     l = TL_checkMemory(2);
  225.     mem = ((p<l) ? p : l)*4096 ;
  226.     if(mem==beforeMem) return;
  227.  
  228.     sprintf(mes1,"%03u,%03u,%03u -> %03u,%03u,%03u\0",
  229.                 beforeMem/1000000,(beforeMem/1000)%1000,beforeMem%1000,
  230.                 mem/1000000,(mem/1000)%1000,mem%1000);
  231.     if(mem>beforeMem)    i = mem - beforeMem ;
  232.             else    i = beforeMem - mem ;
  233.     sprintf(mes2,"%c%03u,%03u,%03u\0",( (mem>beforeMem) ? '+' : '-'),
  234.                 i/1000000,(i/1000)%1000,i%1000);
  235.  
  236.     MMI_SendMessage(MessageID[0],MM_SETMSG,1,mes1);
  237.     MMI_SendMessage(MessageID[1],MM_SETMSG,1,mes2);
  238.     MMI_SendMessage(MessageID[0],MM_SHOW,0);
  239.     MMI_SendMessage(MessageID[1],MM_SHOW,0);
  240.     printf("m:%s (%s)\n",mes2,mes1);
  241.  
  242.     beforeMem = mem ;
  243.  
  244.     return ;
  245. }
  246.  
  247. /*    initDataMGUI:IconID:MJ_ICONL40の呼び出し関数    */
  248. int    quitFunc(kobj, messId, argc, pev, trigger)
  249. int        kobj ;
  250. int        messId ;
  251. int        argc ;
  252. EVENT    *pev ;
  253. int        trigger ;
  254. {
  255.     MMI_SetHaltFlag( TRUE );
  256.     exitFuncRet = NOERR;
  257.     return NOERR ;
  258. }
  259.  
  260.